#include <stdio.h>
#include <stdlib.h>
#include <csp_spu.h>
#include <csp_debug.h>
#include "../fh_test.h"


#define CHANNEL_NAME 42


int global_pid; 


int Run(){

	int data[DATA_SIZE];
	int pid = csp_pid();

	global_pid = csp_pid();

	int i;
	int n __attribute__ ((aligned(16)));
	int interval[2] __attribute__ ((aligned(16)));

	printf("Harvester started with pid %i.\n", pid);


	csp_channel init2harvester = 
		csp_create_channel(ONE2ONE_CHANNEL, INIT2HARVESTER, sizeof(int)*2);
	csp_channel workers2harvester = 
		csp_create_channel(ANY2ONE_CHANNEL, WORKERS2HARVESTER, sizeof(int));


	csp_channel_read(init2harvester, interval);


	for(i=interval[0]; i < interval[1]; i++){	
		csp_channel_read(workers2harvester, &n);
		data[n] = n;
	}

	printf("Harvester sending data to be verified.\n");
	
	csp_channel harvester2verifier = 
		csp_create_channel(ONE2ONE_CHANNEL, HARVESTER2VERIFIER, sizeof(int)*DATA_SIZE);

	csp_channel_write(harvester2verifier, data);




	ASSERT( pid == csp_pid() );
	ASSERT( global_pid == csp_pid() );

	PRINTF_FOR_TESTING("%s terminating on spe #%i with pid %i\n",__FILE__ , csp_spe_id(), pid);

	PRINTF_FOR_TESTING("Nested task with pid=%i terminated with res=%i.\n", pid, res);

	return 0;
}
